{% extends 'blog/base.html' %}
{% load blog_tags %}
{% block title %}Search{% endblock title %}
{% block content %}
{% if query %}
  <h1>Posts containing "{{ query }}"</h1>
  <h3>
    {% with results.count as total_results %}
      Found {{ total_results }} result{{ total_results|pluralize}}
    {% endwith %}
  </h3>
  {% for post in results %}
    <h4><a href="{{ post.get_absolute_url }}">{{post.title}}</a></h4>
  {% empty %}
    <p>There are no results for your query.</p>
  {% endfor %}
  <p><a href="{% url 'blog:post_search' %}">Search again</a></p>
  {% else %}
    <h1>Search for posts</h1>
    <form method="get">
      {{ form.as_p }}
      <input type="submit" value="Search">
    </form>
{% endif %}
{% endblock content %}